﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="../../js/load.js"></script>
</head>

<body>
    <div id="container">
        <div id="formcontainer">
            <form class="layui-form layui-form-pane" id="editform" lay-filter="editform">
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required" style="width: 140px;">key</label>
                            <div class="layui-input-block" style="margin-left: 140px;">
                                <input type="text" name="key" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required"  style="width: 140px;">过期时间（s）</label>
                            <div class="layui-input-block"  style="margin-left: 140px;">
                                <input type="text" name="keyExpire" autocomplete="off" class="layui-input required number" value="-1">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required" style="width: 140px;">数据类型</label>
                            <div class="layui-input-block" style="margin-left: 140px;">
                                <select name="keyType" lay-verify="required" lay-filter="keyType">
                                    <option value="string">string</option>
                                    <option value="list">list</option>
                                    <option value="set">set</option>
                                    <option value="zset">zset</option>
                                    <option value="hash">hash</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row" style="display:none" id="hashKeyRow">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label"  style="width: 140px;">hashKey</label>
                            <div class="layui-input-block" style="margin-left: 140px;">
                                <input type="text" name="hashKey" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row" style="display:none" id="scoreRow">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label"  style="width: 140px;">score</label>
                            <div class="layui-input-block" style="margin-left: 140px;">
                                <input type="text" name="score" autocomplete="off" class="layui-input number" value="0">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">value</label>
                            <div class="layui-input-block">
                                <textarea name="value" autocomplete="off" class="layui-textarea" style="height: 200px;"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div id="opcontainer">
            <button class="layui-btn" onclick="HandleSave()">确认</button>
            <button class="layui-btn layui-btn-primary" onclick="HandleClose()">关闭</button>
        </div>
    </div>
</body>
</html>
<script>
    $(function () {
        var form = layui.form;
        form.on('select(keyType)', function(data){
            $("#hashKeyRow").hide();
            $("#scoreRow").hide();
            if(data.value=="hash") {
                $("#hashKeyRow").show();
            }
            if(data.value=="zset") {
                $("#scoreRow").show();
            }
        });
    })

    function HandleSave() {
        SubmitForm('editform', 'redis/addKey', BeforeSubmit, null, function (result, status) {
            if (result.code == 0) {
                OpenSuccess('添加成功', function (params) {
                    CloseDialog();
                })
            } else {
                OpenFail(result.msg);
            }
        })
    }

    function BeforeSubmit(data) {
        data.dbIndex = GetUrlParam("dbIndex")
        return true;
    }

    function HandleClose() {
        CloseDialog();
    }
</script>